package com.yixiu.study.juc.cyclicbarrier;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * @CalssName T01_CyclicBarrier
 * @Description 栅栏
 * @Author yixiu
 * @Date 2021/6/25 9:36
 * @Verison num1.0
 **/
public class T01_CyclicBarrier {

    public static void main(String[] args) {
//        CyclicBarrier barrier = new CyclicBarrier(20);
//        CyclicBarrier barrier = new CyclicBarrier(20, () -> System.out.println("满人"));

        CyclicBarrier barrier = new CyclicBarrier(20, new Runnable() {
            @Override
            public void run() {
                System.out.println("满人，发车");
            }
        });

        for(int i=0; i<100; i++){
            new Thread(() -> {
                try {
                    barrier.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (BrokenBarrierException e) {
                    e.printStackTrace();
                }

            }).start();


        }


    }

}
